import getua
import requests
from bs4 import BeautifulSoup

def start():
    url = "https://www.kugou.com/yy/html/rank.html"
    headers = {
        "User-Agent": getua.get_ua()
    }
    resp = requests.get(url,headers=headers)
    #print(resp.text)
    soup = BeautifulSoup(resp.text, "lxml")
    song_elements = soup.select('#rankWrap > div.pc_temp_songlist.pc_rank_songlist_short > ul > li > a')
    for song_element in song_elements:
        song_name = song_element.contents[0].text.strip()  # 获取 a 标签中非 span 的内容
        singer = song_element.select_one('span').text.strip()[2:]  # 获取 span 标签的内容
        print(f"抓取到歌曲: {song_name:<10},歌手为: {singer:<30}")

if __name__ == "__main__":
    start()